package com.swordliu.facebook.controller;

import com.swordliu.facebook.pojo.entity.Role;
import com.swordliu.facebook.service.RoleService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.Serializable;
import java.util.List;

/**
 * RoleController
 * Created by SwordLiu on 2017-07-24.
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/roles")
    public String roles(Model model) throws Exception {
        List<Role> roles = roleService.getRoles();
        model.addAttribute("roles", roles);
        return "page/sys/role/role";
    }

    @RequestMapping("/addRole.do")
    @ResponseBody
    @RequiresRoles("sys")
    public boolean addRole(Model model, Role role) {
        try {
            roleService.add(role);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

}
